package com.intellagric.controller.portal.iftmonitor;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.EquipmentChannelVo;
import com.intellagric.pojo.IftChannel;
import com.intellagric.pojo.IftEquipment;
import com.intellagric.pojo.IftEquipmentChannel;
import com.intellagric.service.iftmonitor.ift_equipment.EquipmentService;
import com.intellagric.service.iftmonitor.ift_equipment_channel.EquipmentChannelService;
import com.intellagric.service.iftmonitor.ift_warning_config.WarningConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/12/13
 * @DESC： 采集设备通道管理
 */
@Controller
public class EquipmentChannelController {

    @Autowired
    private EquipmentChannelService equipmentChannelService;

    @Autowired
    private EquipmentService equipmentService;

    @Autowired
    private WarningConfigService warningConfigService;

    /**
     * 多条件查询采集设备通道列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/equipment/channel/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(EquipmentChannelVo equipmentChannelVo) {
        return equipmentChannelService.getEquipmentChannelListByVo(equipmentChannelVo);
    }

    /**
     * 多条件查询采集设备通道列表，并且查询与之对应的预警阈值
     * @return LayuiDataGridResult
     */
    @RequestMapping("/equipment/channelAWarn/query")
    @ResponseBody
    public LayuiDataGridResult getChannelAndWarnByVo(EquipmentChannelVo equipmentChannelVo) {


        //先根据场景下的设备id查到IftEquipmentChannel
        List<IftEquipmentChannel> channelList = equipmentChannelService.getEquipmentChannelListByVo(equipmentChannelVo).getData();
        if (channelList.size() != 0) {
            //查找当前的设备的场景id
            IftEquipment equipment = equipmentService.getEquipmentById(channelList.get(0).getEquipmentId());
            //查询预警值   预警值是场景的预警值
            LayuiDataGridResult result = warningConfigService.getWarningConfigListByScenery(equipment.getSceneId());
            return result;
        }
        return LayuiDataGridResult.fail();
    }

}
